<?php
class DataFriends{
	private $Revision;
	private $FriendsID = array();
	function __construct(){
		$this->Revision = 0;
	}
	static function swap($bytebuffer){
		$obj = new DataFriends();
		$obj->Revision = DataUtil::readInt32( $bytebuffer ) ;
		$nof_friends = DataUtil::readInt32( $bytebuffer ) ;
		for($i = 0; $i < $nof_friends; $i++){
			$obj->FriendsID[] = DataUtil::readInt32( $bytebuffer ) ;
		}
		return $obj;
	}
	function isFriend($fid){
		if(is_array($this->FriendsID)){
			foreach($this->FriendsID as $id){
				if($fid == $id)return true;
			}
		}
		return false;
	}
	function getRivision(){
		return $this->Revision;
	}
	function getFriendsID(){
		return $this->FriendsID;
	}
	function addFriend($fid){
		if(is_array($this->FriendsID)){
			foreach($this->FriendsID as $id){
				if($fid == $id)return false;
			}
		}
		$this->FriendsID[] = $fid;
		$this->Revision = ($this->Revision + 1)%500000;
		return true;
	}
	function getBinSize(){
		$size = 0;
		$size += 4 ;
		$size += 4 ;
		$size += count($this->FriendsID) * 4 ;
		return $size;
	}
	function getBinary(){
		$buf = ByteBuffer::allocate( $this->getBinSize() ) ;
		DataUtil::writeInt32( $buf , $this->Revision ) ;
		DataUtil::writeInt32( $buf , count($this->FriendsID) ) ;
		if(is_array($this->FriendsID)){
			foreach($this->FriendsID as $fid){
				DataUtil::writeInt32( $buf , $fid ) ;
			}
		}
		return  $buf ->_array() ;
	}
}
?>